<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopUserGoodsLogTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_user_goods_log', ['comment' => '用户商品收藏', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('goods_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '商品'])
            ->addColumn('user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn(Column::enum('type', ['favorite', 'views'])->setNull(true)->setDefault(null)->setComment('类型:favorite=收藏,views=浏览记录'))
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('goods_id')
            ->addIndex('user_id')
            ->addIndex('type')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_user_goods_log');
        $table->drop();
    }
}
